package com.example.spring_boot;

import com.example.spring_boot.bean.Dog;
import com.example.spring_boot.bean.DogCompent;
import jakarta.annotation.PostConstruct;
import jakarta.annotation.PreDestroy;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class BeanLifeComponent implements BeanNameAware {


    private Dog singletonDog;
//实体化
    public BeanLifeComponent() {
        System.out.println("定义 执行构造函数");
    }
    @Resource(name = "singletonDog")
    public void setDogCompent(Dog singletonDog) {
    System.out.println("设置属性值"+singletonDog);
        this.singletonDog = singletonDog;
    }

    @Override
    public void setBeanName(String name) {
        System.out.println("执行此方法");
    }

    //初始化
    @PostConstruct
    public void PostConstruct(){
        System.out.println("执行PostConstruct");
    }

    public void use(){
        System.out.println("执行了use方法");
    }
    //销毁

    @PreDestroy
    public void PreDestory(){
        System.out.println("执行了PreDestory");
    }
}
